Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Batch Exports Filters UI #22857

Closed
wants to merge 26 commits into from

Conversation

benjackwhite
Copy link
Contributor

@benjackwhite benjackwhite commented Jun 10, 2024

Problem

WIP - Adds the same UI as the Hog functions have

Changes

TODO

  • Use the same logic from hog functions to generate the relevant HogQL / Hog if possible
  • Actually implement the filtering

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

3 snapshot changes in total. 0 added, 3 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

Copy link
Contributor

github-actions bot commented Jun 11, 2024

Size Change: +48 B (0%)

Total Size: 1.06 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 1.06 MB +48 B (0%)

compressed-size-action

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

3 snapshot changes in total. 0 added, 3 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@benjackwhite benjackwhite marked this pull request as ready for review June 11, 2024 08:34
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

return [int(action["id"]) for action in filters.get("actions", [])]


def hog_function_filters_to_expr(filters: dict, team: Team, actions: dict[int, Action]) -> ast.Expr:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of hard to understand the resulting expression from reading the function. Are there any examples we could look at? Potentially in a test case to ensure this thing works?

Copy link
Contributor

@tomasfarias tomasfarias Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am mostly interested in the rough shape of the sql an action filter transpiles to, as I have concerns about performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My knowledge here breaks down but maybe @mariusandra can be of help?
It populates to the same expression that a HogQL expression would be, but I'm not sure what the correct way of then using it in a clickhouse query is tbh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be as well that the whole code there doesn't apply for batch exports so we can definitely un-abstract it if thats the case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I did have some follow-up questions regarding how actions would interact with batch exports:

  • What if some of the events that compose the action fall in a previous batch? Should that action be included in the current batch? I guess these questions fall under "When does an action happen?".
  • Should we extend the schema with an action_id?
  • General concerns about performance giving that filter fields may not be in the sort key, and sampling is not a valid strategy for batch exports.

I hoped seeing the SQL would help me clarify these. In the meantime though, it may be easier to limit to event filters only for batch exports, as we already work with those, and they are part of the sort key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, actions are just events and properties anyways (other than cohorts but those will not cause a compile error so also don't apply.
If you think of an "Action" as a "Saved Filter" then it is easier to reason on in that I would say it should simply filter the data being exported


updates = BatchExport.objects.bulk_update(affected_batch_exports, ["filters"])

# TODO Publish update to batch export processor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hard part will be updating the processor to work with filters. Publishing will not be possible until that point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, hence the "TODO" 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I would be taking this TODO as this looks overall pretty nice, just wanted to clarify the changes are more in the posthog/temporal/batch_exports files than here.

# Conflicts:
#	frontend/__snapshots__/scenes-app-insights--trends-line-edit--dark.png
#	frontend/__snapshots__/scenes-app-insights--trends-line-edit--light.png
#	frontend/src/lib/constants.tsx
#	frontend/src/scenes/pipeline/hogfunctions/PipelineHogFunctionConfiguration.tsx
#	frontend/src/scenes/pipeline/hogfunctions/pipelineHogFunctionConfigurationLogic.tsx
#	latest_migrations.manifest
#	posthog/models/hog_functions/hog_function.py
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

3 snapshot changes in total. 0 added, 3 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@posthog-bot
Copy link
Contributor

This PR was closed due to lack of activity. Feel free to reopen if it's still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants